package com.njtcedu.microblog.common.web.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class LogFilter implements Filter {
	private final Logger logger = LoggerFactory.getLogger(LogFilter.class);
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		long start = System.currentTimeMillis();
		String address = request.getRemoteAddr();
		String file = ((HttpServletRequest) request).getRequestURI();
		chain.doFilter(request, response);
		logger.info("User access! " + " User IP: " + address + " Resource: "
				+ file + " Milliseconds used: "
				+ (System.currentTimeMillis() - start));

	}

	public void init(FilterConfig arg0) throws ServletException {
	}

	public void destroy() {
	}

}
